using System;
using System.IO;
using System.Windows;
using Qplus.Infrastructure;
using System.Diagnostics;

namespace Qplus.Commands
{

    /**
     * 
     * 获取推荐用户列表
     * （1 推荐用户 2 推荐聊天室）
     * @
     */
    public class GetChatListCommand : AbsHeaderHttpCommand , HttpInputStreamProcessor{

	    const String COMMAND = "GetChatList";

        public event EventHandler<MessageReceivedFromServer> GetChatListCommandReceivedFromHttpServer;

	    /**
	     * @param uid
	     * @param UKEY
	     */
	    public GetChatListCommand(String uid, String UKEY)
            : base(COMMAND, uid, UKEY)
        {
		    
	    }
	

	    
	    public override Boolean processInputStream(Stream responseStream) {
            return true;
	    }
	
	    //public void onGetChatList(List<UserInfo> users, List<Room> rooms){}
	
	    public HttpTask execute(String url) {
            base.MessageReceivedFromHttpServer += new EventHandler<MessageReceivedFromServer>(GetChatListCommand_MessageReceivedFromHttpServer);
		    return base.execute(url, this);
	    }
        void GetChatListCommand_MessageReceivedFromHttpServer(object sender, MessageReceivedFromServer e)
        {
            //throw new NotImplementedException();
            string data = System.Text.UTF8Encoding.UTF8.GetString(e.Message, 0, e.Message.Length);
            Debug.WriteLine(data);
            ProcessIncomingMessage(data);
        }
        private void ProcessIncomingMessage(string ReceivedMessage)
        {
            // Future hook for handling the message in somewhere else.
            // It's most probably wise to put the parsing logic in some other class.
            if (GetChatListCommandReceivedFromHttpServer != null)
                GetChatListCommandReceivedFromHttpServer(this, new MessageReceivedFromServer(ReceivedMessage));
        }
    }

}
